package com.kwan.xframe.common.bean;

import android.app.Activity;
import android.graphics.Color;

import com.kwan.xframe.BR;
import com.kwan.xframe.R;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

public class TitleEntity extends BaseObservable {

	private String title;
	private int titleSize;
	private int leftLayoutId;
	private Activity activity;

	private int titleColor = Color.WHITE;


	public TitleEntity(Activity activity) {
		this.activity = activity;
	}

	public TitleEntity() {
	}


	@Bindable
	public Activity getActivity() {
		return activity;
	}

	public TitleEntity setActivity(Activity activity) {
		this.activity = activity;
		return this;
	}

	@Bindable
	public int getTitleColor() {
		return titleColor;
	}

	public TitleEntity setTitleColor(int titleColor) {
		this.titleColor = titleColor;
		notifyPropertyChanged(BR.titleColor);
		return this;
	}

	@Bindable
	public String getTitle() {
		return title;
	}

	public TitleEntity setTitle(String title) {
		this.title = title;
		notifyPropertyChanged(BR.title);
		return this;
	}

	@Bindable
	public int getTitleSize() {
		return titleSize;
	}

	public TitleEntity setTitleSize(int titleSize) {
		this.titleSize = titleSize;
		notifyPropertyChanged(BR.titleSize);
		return this;
	}


	private int backTintColor = Color.WHITE;

	@Bindable
	public int getBackTintColor(){
		return backTintColor;
	}

	public TitleEntity setBackTintColor(int color) {
		this.backTintColor = color;
		notifyPropertyChanged(BR.backTintColor);
		return this;
	}


	@Bindable
	public int getLeftLayoutId() {
		return leftLayoutId;
	}

	public TitleEntity setLeftLayoutId(int leftLayoutId) {
		this.leftLayoutId = leftLayoutId;
		notifyPropertyChanged(BR.leftLayoutId);
		return this;
	}

	public void leftClick() {
		if (clickListener != null)
			clickListener.onLeftClick(activity);
	}


	public interface ClickListener {
		void onLeftClick(Activity activity);
	}

	private ClickListener clickListener;

	public ClickListener getClickListener() {
		return clickListener;
	}

	public TitleEntity setClickListener(ClickListener clickListener) {
		this.clickListener = clickListener;
		return this;
	}


	public static TitleEntity getCommonInstance(Activity activity) {

		return new TitleEntity()
				.setActivity(activity)
				.setTitle("null")
				.setTitleSize(48)
				.setLeftLayoutId(R.layout.layout_titlebar_back)
				.setClickListener(new ClickListener() {
					@Override
					public void onLeftClick(Activity activity) {
						if (activity != null)
							activity.onBackPressed();
					}
				});

	}


}
